package com.xie.o2o.controller.frontend;

import com.google.common.collect.Maps;
import com.xie.o2o.entity.Product;
import com.xie.o2o.service.ProductService;
import com.xie.o2o.util.HttpServletUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 获取商品详情
 * @create: xie
 */
@Controller
@RequestMapping("/frontend")
public class ProductDetailController {
    private final static Logger log = LoggerFactory.getLogger(ProductDetailController.class);

    @Autowired
    private ProductService productService;

    @ResponseBody
    @RequestMapping(value = "/listproductdetailpageinfo", method = RequestMethod.GET)
    public Map<String, Object> listProductDetail(HttpServletRequest request) {
        Map<String, Object> map = Maps.newHashMap();
        long productId = HttpServletUtil.getLong(request, "productId");
        Product product;
        if (productId != -1) {
            product = productService.getProductById(productId);
            map.put("product", product);
            map.put("success", true);
        } else {
            map.put("success", false);
            map.put("errMsg", "empty prodcutId");
        }
        return map;
    }
}
